package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.website.util.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/images")
public class UploadImagesController {

    @Value("${file.dir}")
    private String dir;

    @RequestMapping("")
    @ResponseBody
    public Map apliuoadImg(MultipartFile pic){
        Map<Object, Object> map = new HashMap<>();
        if(pic != null && pic.getSize() > 0){
            String url = UploadUtil.upload(pic, dir);
            url = "/" + url;
            map.put("url",url);
            map.put("status",1);
        }else {
            map.put("status",0);
            map.put("msg","上传失败");
        }
        return map;
    }
}
